import java.util.Stack;

/**
 * 
 * @author s3rv4nt
 *
 */
public class ContextStack
{
	private Stack<Context> contextStack;
	
	public ContextStack()
	{
		contextStack = new Stack<Context>();
	}
	
	public String popName()
	{
		return contextStack.pop().getName();
	}
	
	public String peekName()
	{
		return contextStack.peek().getName();
	}
	
	public int peekDepth()
	{
		if(!isEmpty())
			return contextStack.peek().getDepth();
		
		return -1;
	}
	
	public Context push(String name, int depth)
	{
		return contextStack.push(new Context(name, depth));
	}
	
	public boolean isEmpty()
	{
		return contextStack.isEmpty();
	}
	
	public String toString()
	{
		String output = "< ";
		int amt = contextStack.size();
		
		if(amt == 0)
			return "";
		
		for(int i = 0; i < amt; i++)
		{
			output += contextStack.get(i).getName();
			if(i != amt - 1)
				 output += ": ";
		}
		output += " > ";
		
		return output;
	}
	
	private class Context 
	{
		private String name;
		private int depth;
		
		public Context(String name, int depth)
		{
			this.name = name;
			this.depth = depth;
		}
		
		public int getDepth()
		{
			return depth;
		}
		
		public String getName()
		{
			return name;
		}
		
		public String toString()
		{
			return name + ": ";
		}	
	}
}
